package com.piesat.feaedit.feaedit.base.response;


import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;

public class BaseResponse implements Serializable {

    private static final String STATUS_SUCCESS = "OK";
    private static final String STATUS_FAILURE = "FAILURE";

    private String status;

    private String message;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Long total;

    public BaseResponse() {
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public BaseResponse(String status, String message) {
        this.status = status;
        this.message = message;
    }

    public BaseResponse(String status, String message, Object data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public BaseResponse(String status, String message, Object data, Long total) {
        this.status = status;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    public static BaseResponse failure(String message) {
        return new BaseResponse(STATUS_FAILURE, message);
    }

    public static BaseResponse failure(Integer code, String message) {
        return new BaseResponse(code + "", message);
    }

    public static BaseResponse success(String message) {
        return new BaseResponse(STATUS_SUCCESS, message);
    }

    public static BaseResponse success(String message, Object data) {
        //if (data instanceof Page) {
        //    return new BaseResponse(STATUS_SUCCESS, message, ((Page) data).getContent(), ((Page) data).getTotalElements());
        //} else {
            return new BaseResponse(STATUS_SUCCESS, message, data);
        //}
    }

    public static BaseResponse success(String message, Object data, long count) {
        return new BaseResponse(STATUS_SUCCESS, message, data, count);
    }




}
